package com.atguigu.Flink.datastream.transform;

import com.atguigu.Flink.POJO.Event;
import com.atguigu.Flink.POJO.WordCount;
import com.atguigu.Flink.function.ClickSource;
import org.apache.flink.api.common.functions.FlatMapFunction;
import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.api.java.functions.KeySelector;
import org.apache.flink.connector.file.src.FileSource;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.TSFBuilder;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.util.Collector;

public class Flink02_SimpleAgg {
    public static void main(String[] args) {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);
        DataStreamSource<Event> ds = env.addSource(new ClickSource());
        ds.print("input");
//        ds.map(new MapFunction<Event, WordCount>() {
//            @Override
//            public WordCount map(Event event) throws Exception {
//                return new WordCount(event.getUser(),1L);
//            }
//        }).keyBy(new KeySelector<WordCount, String>() {
//            @Override
//            public String getKey(WordCount wordCount) throws Exception {
//                return wordCount.getWord();
//            }
//        }).sum("count")
//                .print();
        ds.keyBy(event -> event.getUser()).maxBy("ts").print("max");


        try {
            env.execute();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
